package javabase.schoolwork.jdbc;

import java.sql.*;



/**
 * @author fance
 * @date 2018/6/5 10:06
 */
public final class DBUtil {
    public static final String DBDRIVER = "com.mysql.jdbc.Driver";
    public static final String DBURL = "jdbc:mysql://localhost:3306/test";
    public static final String DBUSER = "root";
    public static final String DBPASS = "123456";

    static {
        try {
            Class.forName(DBDRIVER);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(DBURL, DBUSER, DBPASS);
    }
    public static void update(Connection conn, String sql) throws SQLException {
        Statement stmt = conn.createStatement();
        if(stmt.executeUpdate(sql) > 0) {
            System.out.println("success");
        } else {
        System.out.println("fail");
    }
    }
    public static ResultSet select(Connection conn, String sql) throws SQLException {
        Statement stmt=conn.createStatement();
        return stmt.executeQuery(sql);
    }

}
